package com.cw.part3.config;

import com.alibaba.druid.support.http.StatViewServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

//添加确定当前类是一个配置类的注解
@Configuration
public class DruidConfig {

    @Bean//等价于在原来的xml文件中，配置<bean xxx class="ServletRegistrationBean" />
    public ServletRegistrationBean<StatViewServlet> druidStatViewServlet() {
        //druid默认的访问地址： http://ip:port/druid/index.html
        ServletRegistrationBean<StatViewServlet> registrationBean = new ServletRegistrationBean<>(new StatViewServlet(), "/druid/*");
        // IP白名单 (没有配置或者为空，则允许所有访问)
//        registrationBean.addInitParameter("allow", "127.0.0.1");
        // IP黑名单 (存在共同时，deny优先于allow)
//        registrationBean.addInitParameter("deny", "");
        // 设置登录druid后台的帐号
        registrationBean.addInitParameter("loginUsername", "druid");
        // 设置登录druid后台的密码
        registrationBean.addInitParameter("loginPassword", "druid");
        registrationBean.addInitParameter("resetEnable", "false");
        return registrationBean;
    }
}
